﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../../binary/dynaload.js?28" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="/Resources/easyui-1.32/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="/Resources/easyui-1.32/themes/icon.css" />
    <link href="../../../lhgdialog/lhgdialog.css" rel="stylesheet" type="text/css" />
    <script src="../../../lhgdialog/lhgcore.min.js" type="text/javascript"></script>
    <script src="../../../lhgdialog/_lhgdialog.js" type="text/javascript"></script>
    <style type="text/css">
        .lockrow
        {
            background-color: #d8f2ea;
        }
        .lockcol
        {
            background-color: #d8f2ea;
        }
        .selected
        {
            background-color: #d8f2ea;
        }
        .error
        {
            background-color: #FF0000;
            color: White;
        }
        
        .modified
        {
            background-color: #00ff90;
        }
    </style>
    <script type="text/javascript" src="/Resources/easyui-1.32/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/Resources/easyui-1.32/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/Resources/JSON-js-master/json2.js"></script>
    <script type="text/javascript" src="/Resources/xiaovcn/scripts/usercheck.js"></script>
    <script type="text/javascript" src="/Resources/xiaovcn/scripts/easyuigrid-ext.js"></script>
    <script type="text/javascript">


        $(document).ready(function () {
            var lastIndex;//new
            $('#tt').datagrid({
//                url: '#DataGrid_Url#',
                title: '#DataGrid_Title#', rownumbers: false,height: 60, fitColumns: false, singleSelect: true, striped: true,
                
                toolbar: [
                {
                text: '新增子节点',
                iconCls: 'icon-add',        
                disabled:#DataGrid_ToolBar_InsertChild#,
                handler: function () {
                      var currentrow=AF.func("GetCurrentRow","");
                      var sfmj=AF.func("GetCellData",currentrow+"\r\nsfmj");
                      if(sfmj=="")                      {
                        alert("只能在最后节点前添加");
                      }
                      else                      {
                        var dwbm= $('#dwbm').val();
                        var nf = $('#year').val();
                        var yf= $('#month').val();
                      var zbbm=AF.func("GetCellData",currentrow+"\r\nzbbm");
                      var cj=AF.func("GetCellData",currentrow+"\r\ncj");
                        InsertChild('#DataGrid_Tn#',nf,yf,dwbm,zbbm,cj);   
                      }
                    }
                },'-',{
                    text: '删除行',
                    iconCls: 'icon-remove',        
                    disabled:#DataGrid_ToolBar_Delete#,
                    handler: function () {
                      var currentrow=AF.func("GetCurrentRow","");
                      var sfmj=AF.func("GetCellData",currentrow+"\r\n12");
                      if(sfmj=="")                   {
                            if(confirm('确定要删除吗？'))
                            {
                        var dwbm= $('#dwbm').val();
                        var nf = $('#year').val();
                        var yf= $('#month').val();
                      var zbbm=AF.func("GetCellData",currentrow+"\r\n1");
                      var rowid=AF.func("GetCellData",currentrow+"\r\nrowid");
//                      alert(cj);
                        DeleteRow('#DataGrid_Tn#',rowid,zbbm,nf,yf,dwbm); 
                          }
                      }
                    }
                },'-',{
                    text: '保存',
                    iconCls: 'icon-save',                    
                    disabled:#DataGrid_ToolBar_Save#,
                    handler: function () {
                        //$('#tt').datagrid('acceptChanges');
                        if(confirm('确定保存？'))
                        {
                            $('#toolbardiv').window({ width:230,height:70,modal:true });  
                        SaveData();  
                                      }       
                    }
                },'-',{
                    text: '清空',
                    iconCls: 'icon-cancel',             
                    disabled:#DataGrid_ToolBar_Clear#,
                    handler: function () {
                        if(confirm('确定要清空并重建本表数据吗？'))
                        {
                            var a1= $('#dwbm').val();
                            var a2 = $('#year').val();
                            var a3= $('#month').val();
                            $('#toolbardiv').window({ width:230,height:70,modal:true });          
                            ClearReport('#DataGrid_Tn#',a1,a2,a3);                
                        }
                    }
                },'-',{
                    text: '计算',
                    iconCls: 'icon-reload', 
                    disabled:#DataGrid_ToolBar_Compute#,
                    handler: function () {
                        if(confirm('确定要计算本表数据吗？'))
                        {
                            var a1= $('#dwbm').val();
                            var a2 = $('#year').val();
                            var a3= $('#month').val();
                            $('#toolbardiv').window({ width:230,height:70,modal:true });  
                            Compute('#DataGrid_Tn#',a1,a2,a3); 
//            $("#toolbardiv").show();
                        }
                    }
                },'-',{
                    text: '提取',
                    iconCls: 'icon-reload',             
                    disabled:#DataGrid_ToolBar_Featch#,                    
                    handler: function () {
                        if(confirm('确定要从其他表提取数据吗？'))
                        {
                            var a1= $('#dwbm').val();
                            var a2 = $('#year').val();
                            var a3= $('#month').val();
                            $('#toolbardiv').window({ width:230,height:70,modal:true });     
                            Featch('#DataGrid_Tn#',a1,a2,a3);       
                        }
                    }
                },'-',{
                    text: '汇总',
                    iconCls: 'icon-sum',          
                    disabled:#DataGrid_ToolBar_Sum#,     
                    handler: function () {
                        if(confirm('确定要汇总本表数据吗？'))
                        {
                            var a1= $('#dwbm').val();
                            var a2 = $('#year').val();
                            var a3= $('#month').val();
                            $('#toolbardiv').window({ width:230,height:70,modal:true });          
                            Sum('#DataGrid_Tn#',a1,a2,a3);  
                        }
                    }
                },'-',{
                    text: '继承',
                    iconCls: 'icon-redo',         
                    disabled:#DataGrid_ToolBar_Carry#,     
                    handler: function () {
                        if(confirm('注意：将会覆盖本表数据，不可恢复，确定要拷贝上一次的数据吗？'))
                        {
                            var a1= $('#dwbm').val();
                            var a2 = $('#year').val();
                            var a3= $('#month').val();
                            Carryon('#DataGrid_Tn#',a1,a2,a3,'#DataGrid_LastYear#','#DataGrid_LastMonth#');          
                        }
                       //window.open("exportxls.aspx?tn=#DataGrid_Tn#&dwbm="+a1+"&year="+a2+"&month="+a3+"",'blank');
                    }
                }
//                ,'-',{
//                    text: '校验',
//                    iconCls: 'icon-help',      
//                    handler: function () {
//                    alert("校验");
//                    }
//                },'-',{
//                    text: '上报',
//                    iconCls: 'icon-help',      
//                    handler: function () {
//                    alert("上报");
//                    }
//                },'-',{
//                    text: '审核通过',
//                    iconCls: 'icon-help',      
//                    handler: function () {
//                    alert("审核通过");
//                    }
//                },'-',{
//                    text: '审核不通过',
//                    iconCls: 'icon-help',      
//                    handler: function () {
//                    alert("审核不通过");
//                    }
//                }
                ]
            });
        });


        function ReloadGrid()
        {
//            $('#tt').datagrid('reload');
            var tableName = '#DataGrid_Tn#';
            var dwbm = $('#dwbm').val();
            var nf = $('#year').val();
            var yf = $('#month').val();
//            AF.func("Build","/SZBBTree/t1.xml");
            AF.func("Build", "/SZBBTree/InitTable.aspx?tableName=" + tableName + "&dwbm=" + dwbm + "&nf=" + nf + "&yf=" + yf);
            ReloadGridData();
        }

        function ReloadGridData()
        {
            var tableName = '#DataGrid_Tn#';
            var dwbm = $('#dwbm').val();
            var nf = $('#year').val();
            var yf = $('#month').val();
            AF.func("Load", "/SZBBTree/InitTableData.aspx?tableName=" + tableName + "&dwbm=" + dwbm + "&nf=" + nf + "&yf=" + yf);   
            SetGridPro();     
        }
       

        function Sum(tn,dwbm,year,month)
        {
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/Sum.aspx',
                data: { tn: tn,year:year,month:month,dwbm:dwbm },
                datatype: 'text',
                success: function (result) { alert('汇总完成');
                $('#toolbardiv').window('close');
            $("#toolbardiv").hide();
                ReloadGrid();   },
                error: function (result) { alert(result.responseText); },
            });  
        }

        function Carryon(tn,dwbm,year,month,preyear,premonth)
        {
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/CarryOn.aspx',
                data: { tn: tn,year:year,month:month,dwbm:dwbm,preyear:preyear,premonth:premonth },
                datatype: 'text',
                success: function (result) { alert('复制上次数据完成'); ReloadGrid(); },
                error: function (result) { alert(result.responseText); },
            });  
        }
        function Featch(tn,dwbm,year,month)
        {
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/Featch.aspx',
                data: { tn: tn,year:year,month:month,dwbm:dwbm },
                datatype: 'text',
                success: function (result) { alert('提取完成');
                             $('#toolbardiv').window('close');
            $("#toolbardiv").hide();       
            ReloadGrid(); },
                error: function (result) { alert(result.responseText); },
            });  
        }
        function LockReport(tn,dwbm,year,month)
        {
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/Report.aspx',
                data: { tn: tn,year:year,month:month,dwbm:dwbm },
                datatype: 'text',
                success: function (result) { alert('上报成功');ReloadGrid(); },
                error: function (result) { alert(result.responseText); },
            });  
        }

        function ClearReport(tn,dwbm,year,month)
        {
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/ClearReport.aspx',
                data: { tn: tn,year:year,month:month,dwbm:dwbm },
                datatype: 'text',
                success: function (result) { alert('数据已清空'); 
                  $('#toolbardiv').window('close');
            $("#toolbardiv").hide();ReloadGrid();},
                error: function (result) { alert(result.responseText); },
            });  
        }

        function DeleteRow(tn,rowid,zbbm,year,month,dwbm){
//            SaveData();//先保存数据
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/DeleteRow.aspx',
                data: { rowid: rowid ,tn:tn,zbbm:zbbm,year:year,month:month,dwbm:dwbm},
                datatype: 'html',
                success: function (result) { ReloadGrid(); },
                error: function (result) { alert(result.responseText); },
            });     
        }

        function InsertRow(tn,dwbm,year,month)
        {
            SaveData();//先保存数据
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/InsertRow.aspx',
                data: { tn: tn,year:year,month:month,dwbm:dwbm },
                datatype: 'text',
                success: function (result) { ReloadGrid();},
                error: function (result) { alert(result.responseText); },
            });        
        }

        function InsertChild(tn,year,month,dwbm,zbbm,cj)
        {
//            SaveData();//先保存数据
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/InsertChild.aspx',
                data: { tn: tn,year:year,month:month,dwbm:dwbm,zbbm:zbbm,cj:cj },
                datatype: 'text',
                success: function (result) {ReloadGrid(); },
                error: function (result) { alert(result.responseText); },
            });        
        }

        function UpdateTBSJ(tn,year,month,dwbm)
        {            
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/UpdateTbsj.aspx',
                data: { tn: tn,year:year,month:month,dwbm:dwbm},
                datatype: 'text',
                success: function (result) {},
                error: function (result) { alert(result.responseText); },
            });        
        }

        function Compute(tn,dwbm,nf,yf)
        {
            var xml = AF.func("GetChangedXML", "level=1");
//            if (xml == null || xml == "") {
//                AF.func("MessageBoxFloat", "请先作增、删、改操作!	");
//            }
////            alert(xml);
            $.ajax({
                type: 'post',
                url: '/PluginSrc/StatisticalSystem/Compute.aspx',
                data: { tn: tn, nf: nf, yf: yf, dwbm: dwbm,xml:xml },
                datatype: 'text',
                success: function (result) { alert('计算完成'); 
                             $('#toolbardiv').window('close');
                               $("#toolbardiv").hide();       
                             ReloadGridData();  
                             },
                error: function (result) { alert(result.responseText); },
            });  
//SaveData();
        }

        //更新数据
        function SaveData() {       
            var dwbm= $('#dwbm').val();
            var nf = $('#year').val();
            var yf= $('#month').val();
            var tableName='#DataGrid_Tn#';
            var xml = AF.func("GetChangedXML", "level=1");
//            alert(xml);
            if (xml == null || xml == "") {
                AF.func("MessageBoxFloat", "请先作增、删、改操作!	");
                  $('#toolbardiv').window('close');
            $("#toolbardiv").hide();    
            }
            else if (xml != "0") {
                $.ajax({
                    type: "post",
                    url: "/SZBBTree/SaveTable.aspx",
                    dataType: "json",
                    data: { nf: nf, yf: yf, dwbm: dwbm, tableName: tableName, xml: xml },
                    success: function (data) {
                        var jsonData = data;
                        if (jsonData.save == 0)
                        { alert("保持失败"); }
                        else
                        { alert("保持成功"); }
                  $('#toolbardiv').window('close');
            $("#toolbardiv").hide();
                             ReloadGridData();  
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(errorThrown);
                    }
                });
            }              
        }



    </script>
    <script type="text/javascript" language="JavaScript">
        function OnReady(id) {
            ReloadGrid();
        }
        function OnEvent(id, Event, p1, p2, p3, p4) {
            if (Event == "MenuBeforePopup") {
                var name1 = "数据穿透";
                var name2 = "修改记录";
                var enable = "true";
                if (p1 != "-1") {  //右击在某行
                    name1 = name1;
                    name2 = name2;
                }
                else
                    enable = "false";
                var menu = "id=4001; text=" + name1 + "; enabled=" + enable + "\r\n";
                menu += "id=4002; text=" + name2 + "; enabled=" + enable + "\r\n";
                AF.func("AddMenu", menu);
            }
            else if (Event == "MenuClicked") {
                //                AF.func("MessageBoxFloat", "触发了js事件！\\r\\n\\r\\n自定义功能号(id)：" + p1 + "\\r\\n\\r\\n行：" + p2 + ",  列：" + p3);

                if (p1 == 4001) {
                    J('#AF').dialog({ title: '示例', cover: true, page: '../../../demo/ct.htm' });
                }
                else if (p1 == 4002) {
                    J('#AF').dialog({ title: '示例', cover: true, page: '../../../demo/lsjl.htm' });

                }
            }

            if (p3 == "") {
                return;
            }
            if (Event == "EditChanged") {
                var endcol = AF.func("GetNextValidCol", p4);
                var endrow = parseInt(p3) + 1;
                //                alert(parseInt(p3) + 1);
                for (var row = p1; row < endrow; row++) {
                    for (var col = p2; col != endcol; col = AF.func("GetNextValidCol", col)) {
                        var data = AF.func("GetCellData", row + "\r\n" + col);
                        //                        alert(parseInt(data));
                        if (data == 0) {
                            //                            alert(data);
                            AF.func("SetCellData", row + "\r\n" + col + "\r\n" + "")
                        }
                    }
                }
            }
        }

        function SetGridPro() {
            var nf = $('#year').val();
            var yf = $('#month').val();
            var tableName = '#DataGrid_Tn#';
            var dwbm = $('#dwbm').val();
            $.ajax({
                type: "post",
                url: "/SZBBTree/GetLockCell.aspx",
                dataType: "json",
                data: { nf: nf, yf: yf, tableName: tableName, dwbm: dwbm },
                success: function (data) {
                    var jsonData = data;
                    lockgridcell(jsonData.lockcell);
                    //                    hidegridRow(jsonData.hiderow);
                    //                    hidegridCol("," + jsonData.hidecol + ",");
                    //                    alert(jsonData.ismerge);
                    if (jsonData.ismerge == 1) {
                        AF.func("MergeSame", "col=4");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        }
        function hidegridRow(hiderow) {
            var rows = AF.func("GetRows", "");
            //                alert(hiderow);
            for (var i = 0; i < rows; i++) {
                var zbbm = AF.func("GetCellData", i + "\r\n1");
                //                hiderow = "CL0001";
                if (hiderow != "") {
                    if (hiderow.indexOf(zbbm) >= 0) {
                        AF.func("HideRow", i + "\r\ntrue");
                    }
                }
            }
        }
        function hidegridCol(hiderow) {
            var rows = AF.func("GetCols", "");
            //                            alert(hiderow);
            for (var i = 0; i < rows; i++) {
                //                var zbbm = AF.func("GetCellData", i + "\r\n1");
                //                hiderow = "CL0001";
                if (hiderow != "") {
                    if (hiderow.indexOf("," + i + ",") >= 0) {
                        AF.func("HideCol", i + "\r\ntrue");
                    }
                }
            }
        }
        function lockgridcell(lockcell) {
            if (lockcell == 0)
            { return; }
            var str = lockcell, a = [], b = [], c = [], d = [], temp = str.split(","), i = 0;
            //将字符串用"|"符号分割后存入 temp数组
            for (; i < temp.length; i++) {
                a.push(temp[i].split("_")[0]);
                b.push(temp[i].split("_")[1]); //列
            }
            //            alert(a.join(",") + "\n" + b.join(",")); //将a,b数据元素用","链接，alert出来测试最后结果。
            var cols = AF.func("GetCols", "");
            var rows = AF.func("GetRows", "");
            var zbbm = '', zd = '';
            for (var j = 0; j < a.length; j++) {
                for (var row = 0; row < rows; row++) {
                    zbbm = AF.func("GetCellData", row + "\r\n1");
                    if (zbbm == a[j]) {
                        AF.func("SetCellBackColor", row + "\r\n" + b[j] + "\r\n#C0FFFF");
                        AF.func("SetCellEditAble", row + "\r\n" + b[j] + "\r\nno");
                        break;
                    }
                }
            }
        }
    </script>
</head>
<body>
    <div>
        <div style="padding-bottom: 5px; padding-top: 10px; font-size: 12px; height: 23px;">
            单位：#Select_DWBM# 时间：#Select_Year# #Select_Month#
        </div>
        <div>
            <table id="tt">
            </table>
        </div>
        <div id="dAF" style="position: relative; width: 100%;">
            <script>                insertTreeList('AF', 'Border=single; ')</script>
        </div>
    </div>
    <div id="toolbardiv" style="display: none;">
    </div>
    <script type="text/javascript" language="javascript">
        var height1 = $(window).height();
        var height = height1 * 0.8;
        document.getElementById("dAF").style.height = height.toString() + "px";
    </script>
</body>
</html>
